





CREATE TABLE Invoice
 (
 Id int NOT NULL PRIMARY KEY IDENTITY,
 CustomerId int NOT NULL FOREIGN KEY REFERENCES Customer(Id),
 Name varchar(255),
 Comment varchar(max),
 SubTotal decimal(18,4) NOT NULL,
 FuelSurcharge decimal(18,4),
 Tax decimal(18,4) NOT NULL,
 Total decimal(18,4) NOT NULL,
 Discount decimal(18,4) NOT NULL,
 OrderChargePercentage decimal(18,4) NOT NULL,
 InvoiceGuid uniqueidentifier NOT NULL,
 InvoiceNumber varchar(255) NOT NULL,
 InvoiceStatusId int NOT NULL,
 CreatedOnUtc datetime NOT NULL,
 DueDate datetime
 );

ALTER TABLE "Order"
 ADD InvoiceId int FOREIGN KEY REFERENCES Invoice(Id);
ALTER TABLE "Order"
 ADD OrderKindId int;

CREATE INDEX IX_Invoice_CustomerId
 ON Invoice (CustomerId)